<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->library('session');
		if($this->session->userdata('logged_in')!=TRUE && current_url()!=site_url('admin/login')) {
	        $this->session->set_userdata('last_page', current_url());
	        redirect('/admin/login');
	    }
		$this->load->model('Model_admin');
		$this->data['head'] = $this->load->view('head','',true);
		$this->data['foot'] = $this->load->view('foot','',true);
	}
	
	public function index()
	{
			
	}
	
	public function login()
	{
		$this->load->model('Model_admin');
		if ($this->Model_admin->auth($this->input->post('user',TRUE),$this->input->post('pass')) or $this->session->userdata('logged_in'))
		{
			$this->session->set_userdata('logged_in', TRUE);
			redirect($this->session->userdata('last_page'));
		}
		else
		{
			$this->data['error'] = $this->input->post('user',TRUE).$this->input->post('pass');
			$this->load->view('admin_login',$this->data);
		}
	}
	
	public function logout()
	{
		$this->session->set_userdata('logged_in', FALSE);
		redirect(site_url('admin'));
	}
	
	private function _backend()
	{
		
	}
	
}
